{% extends 'common/base.html' %}

{% load staticfiles %}

{% block head_js %}
    <script src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
    <script>
{#        更新商品总价格#}
        function update_price() {
            num = parseInt($('.num_show').val());
            price = parseInt($('.show_pirze').find('em').html());

            total = num * price;
            $('.total').find('em').html(total+'元');
        }


        $(function () {
            $('.add').click(function () {
{#                # 获取数量#}
                num = $('.num_show').val();
                num = parseInt(num) + 1;
                $('.num_show').val(num);
                update_price();
            });
        });
        $(function () {
            $('.minus').click(function () {
{#                # 获取数量#}
                num = $('.num_show').val();
                num = parseInt(num) - 1;
                if (num <= 0)num = 1;
                $('.num_show').val(num);
                update_price();
            });
        });

        $(function () {
            $('#add_cart').click(function () {
                good_id = $('#goods_id').val();
                good_num = $('.num_show').val();

                $.get('/carts/add_goods/', {'goods_id':good_id, 'goods_num': good_num}, function (total) {
{#                    alert(total['total'])#}
                    $('#show_count').html(total['total'])

                })
            })
        })

    </script>
{% endblock head_js%}


{% block body %}


{% include 'common/status.html' %}


	<div class="search_bar clearfix">
        {% include 'common/logo.html' %}
		<div class="search_con fl">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>
{#            购物车    #}
        {% include 'goods/cart.html' %}
	</div>

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="#" class="fruit">新鲜水果</a></li>
					<li><a href="#" class="seafood">海鲜水产</a></li>
					<li><a href="#" class="meet">猪牛羊肉</a></li>
					<li><a href="#" class="egg">禽类蛋品</a></li>
					<li><a href="#" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="#" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">新鲜水果</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img src="/static/{{ good_info.good_image }}"></div>

		<div class="goods_detail_list fr">
			<h3>{{ good_info.good_name }}</h3>
			<p>{{ good_info.good_compendium }}</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em>{{ good_info.good_price }}</em></span>
				<span class="show_unit">单  位：{{ good_info.good_unit }}</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" value="1">
					<a href="javascript:;" class="add fr">+</a>
					<a href="javascript:;" class="minus fr">-</a>	
				</div> 
			</div>
			<div class="total">总价：<em>{{ good_info.good_price }}元</em></div>
			<div class="operate_btn">
                <input type="hidden" value="{{ good_info.id }}" id="goods_id">
				<a href="javascript:;" class="buy_btn">立即购买</a>
				<a href="javascript:;" class="add_cart" id="add_cart">加入购物车</a>				
			</div>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
                    {% for good in good_new %}
					<li>
						<a href="{% url 'goods:detail' %}?id={{ good.id }}"><img src="/static/{{ good.good_image }}"></a>
						<h4><a href="{% url 'goods:detail' %}?id={{ good.id }}">{{ good.good_name }}</a></h4>
						<div class="prize">￥{{ good.good_price }}</div>
					</li>
                    {% endfor %}
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li class="active">商品介绍</li>
				<li>评论</li>
			</ul>

			<div class="tab_content">
				<dl>
					<dt>商品详情：</dt>
					<dd>{{ good_info.good_details }}</dd>
				</dl>
			</div>

		</div>
	</div>


    {% block end_js %}
    <div class="add_jump"></div>
	<script type="text/javascript" src="{% static "js/jquery-1.12.2.js" %}"></script>
{#	<script type="text/javascript">#}
{##}
{#		$('#add_cart').click(function(){#}
{##}
{#		    var $add_x = $('#add_cart').offset().top;#}
{#		    var $add_y = $('#add_cart').offset().left;#}
{##}
{#		    var $to_x = $('#show_count').offset().top;#}
{#		    var $to_y = $('#show_count').offset().left;#}
{##}
{#		    $(".add_jump").css({'left':$add_y+80,'top':$add_x+10,'display':'block'});#}
{##}
{##}
{#			$(".add_jump").stop().animate({#}
{#				'left': $to_y+7,#}
{#				'top': $to_x+7},#}
{#				"fast", function() {#}
{#					$(".add_jump").fadeOut('fast',function(){#}
{#						$('#show_count').html(2);#}
{#					});#}
{##}
{#			});#}
{#		})#}
{#	</script>#}
    {% endblock end_js %}
{% endblock body %}
